<?php
	class thannhandb
	{
		public function Add($MaHocSinh,$HoTenThanNhan,$Phai,$DiaChi,$NgheNghiep,$QuanHe,$DienThoai)
		{
			$sql = "INSERT INTO `tbl_thannhan`(`MaHocSinh`, `HoTenThanNhan`, `Phai`, `DiaChi`, `NgheNghiep`, `QuanHe`,`DienThoai`)
			VALUES ('$MaHocSinh',".dataservice::slashes($HoTenThanNhan).",'$Phai',".dataservice::slashes($DiaChi).",".dataservice::slashes($NgheNghiep).",".dataservice::slashes($QuanHe).",".dataservice::slashes($DienThoai).")";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaThanNhan)
		{
			$sql = "DELETE FROM `tbl_thannhan` WHERE MaThanNhan = '$MaThanNhan' ";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaThanNhan,$MaHocSinh,$HoTenThanNhan,$Phai,$DiaChi,$NgheNghiep,$QuanHe,$DienThoai)
		{
			$sql = "UPDATE `tbl_thannhan`
			 SET MaHocSinh = '$MaHocSinh',
			 	 HoTenThanNhan = ".dataservice::slashes($HoTenThanNhan).",
				 Phai = '$Phai',
				 DiaChi = ".dataservice::slashes($DiaChi).",				 
				 NgheNghiep = ".dataservice::slashes($NgheNghiep).",				
				 QuanHe = ".dataservice::slashes($QuanHe).",
				 DienThoai = ".dataservice::slashes($DienThoai)."
			 WHERE MaThanNhan = '$MaThanNhan'"; 
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
	
		public function GetList($MaThanNhan,$MaHocSinh,$HoTenThanNhan,$Phai,$DiaChi,$NgheNghiep,$QuanHe,$DienThoai)
		{
			$sql = "SELECT * FROM `tbl_thannhan`,`tbl_hocsinh` WHERE tbl_thannhan.MaHocSinh = tbl_hocsinh.MaHocSinh";
			if($MaThanNhan!="")
				$sql .= " AND tbl_thannhan.MaThanNhan = $MaThanNhan ";
			if($MaHocSinh!="")
				$sql .= " AND tbl_thannhan.MaHocSinh = '$MaHocSinh' ";
			if($HoTenThanNhan!="")
				$sql .= " AND tbl_thannhan.HoTenThanNhan = '$HoTenThanNhan' ";
			if($Phai!="")
				$sql .= " AND tbl_thannhan.Phai = '$Phai' ";
			if($DiaChi!="")
				$sql .= " AND tbl_thannhan.DiaChi = '$DiaChi' ";
			if($NgheNghiep!="")
				$sql .= " AND tbl_thannhan.NgheNghiep = '$NgheNghiep' ";
			if($QuanHe!="")
				$sql .= " AND tbl_thannhan.QuanHe = '$QuanHe' ";	
			if($DienThoai!="")
				$sql .= " AND tbl_thannhan.DienThoai = '$DienThoai' ";		
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		public function Find($MaThanNhan,$MaHocSinh,$HoTenThanNhan,$Phai,$DiaChi,$NgheNghiep,$QuanHe,$DienThoai)
		{
			$sql = "SELECT * FROM `tbl_thannhan`,`tbl_hocsinh` WHERE tbl_thannhan.MaHocSinh = tbl_hocsinh.MaHocSinh";
			if($MaThanNhan!="")
				$sql .= " AND tbl_thannhan.MaThanNhan = $MaThanNhan ";
			if($MaHocSinh!="")
				$sql .= " AND tbl_thannhan.MaHocSinh LIKE '%$MaHocSinh%' ";
			if($HoTenThanNhan!="")
				$sql .= " AND tbl_thannhan.HoTenThanNhan LIKE '%$HoTenThanNhan%' ";
			if($Phai!="")
				$sql .= " AND tbl_thannhan.Phai = '$Phai' ";
			if($DiaChi!="")
				$sql .= " AND tbl_thannhan.DiaChi LIKE '%$DiaChi%' ";
			if($NgheNghiep!="")
				$sql .= " AND tbl_thannhan.NgheNghiep LIKE '%$NgheNghiep%' ";
			if($QuanHe!="")
				$sql .= " AND tbl_thannhan.QuanHe LIKE '%$QuanHe%' ";	
			if($DienThoai!="")
				$sql .= " AND tbl_thannhan.DienThoai LIKE '%$DienThoai%' ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
	}
?>